/*************************************************************************
 *  Copyright © 2023-2030 FXB CO.,LTD. All rights reserved.
 *------------------------------------------------------------------------
 *  公司：Fxb
 *  项目：FXB-AutoDrive
 *  文件：WindowActionItemList.cs
 *  作者：Administrator
 *  日期：2024/8/30 14:55:29
 *  功能：Nothing
*************************************************************************/

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;

namespace SceneViewMenu.Editor
{
    /// <summary>
    /// 行为菜单列表
    /// </summary>
    public class WindowActionItemList : List<SceneViewMenuDrawer.ActionMenuItem>
    {
        /// <summary>
        /// 绘制行为菜单项
        /// </summary>
        public void DrawActionItems()
        {
            if (Count == 0) return;

            EditorGUILayout.BeginVertical(new GUIStyle("Label") { normal = new GUIStyle("TextField").normal }, GUILayout.Height(24 * Count + 5 * Count));

            GUI.color = new Color(0, 1, 0, 0.8f);

            foreach (var component in this)
            {
                EditorGUILayout.Space(2.5F);

                if (GUILayout.Button(component.actionName, GUILayout.Width(120), GUILayout.Height(24)))
                {
                    component.action?.Invoke();
                }
                EditorGUILayout.Space(2.5F);
            }

            GUI.color = Color.white;

            EditorGUILayout.EndVertical();
        }

        /// <summary>
        /// 是否包含行为菜单
        /// </summary>
        /// <param name="itemName"></param>
        /// <returns></returns>
        public bool IsContainActionItem(string itemName)
        {
            return this.FirstOrDefault(itme => itme.actionName == itemName) != null;
        }
    }
}


